package com.jerkin.stream;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.stream.Stream;

/**
 * @version V1.0
 * @ClassName: LambdaStream
 * @Description:
 * @author: huhongzhi
 * @date: 2020/8/4 23:15
 */
public class LambdaStream {

    public static void main(String[] args) {
        List<Integer> x = Stream.of(Lists.newArrayList(1),
                Lists.newArrayList(2),
                Lists.newArrayList(3),
                Lists.newArrayList(4),
                Lists.newArrayList(5))
                .parallel().reduce(Lists.newArrayList(1), (v1, v2) -> {
                    v1.addAll(v2);
//                    System.out.println("计算的结果:" + v1);
                    return v1;
                }, (v1, v2) -> {
                    v1.addAll(v2);
//                    System.out.println("参数v1:" + v1 + "参数v2:" + v2 + "局部计算的结果:" + v1);
                    return v1;
                });

        System.out.println("并行结果:" + x);

//        Integer y = Stream.of(1, 2, 3, 4, 5, 6).reduce(1, (v1, v2) -> {
//            System.out.println("参数v1:"+v1+"参数v2:"+v2+"局部计算的结果:"+(v1+v2));
//            return v1 + v2;
//        }, (v1, v2) -> {
//            System.out.println("参数v1:"+v1+"参数v2:"+v2+"局部计算的结果:"+(v1+v2));
//            return v1 + v2;
//        });

//        System.out.println("非行结果:" + y);
    }
}
